<template>
  <div class="user">
    <div class="yanse">
      <div class="user_head">
        <div class="head_lfet">
          <p class="portrait">
            <img :src="img" alt="" style="width: 100%">
            <van-uploader max-count="1" :after-read="afterRead"/>
          </p>
          <p class="user_m">{{this.titleName}}</p>
        </div>
        <div class="head_right">
          <van-icon class="ic_size ic_left" name="friends-o" />
          <van-icon @click="T_SetUp" class="ic_size" name="setting-o" />
        </div>
      </div>
      <ul class="user_ul">
        <li>
          <span>34</span>
          <p>收藏夹</p>
        </li>
        <li>
          <span>8</span>
          <p>关注</p>
        </li>
        <li>
          <span>57</span>
          <p>足迹</p>
        </li>
        <li>
          <span>4</span>
          <p>红包卡卷</p>
        </li>
      </ul>
    </div>
    <van-grid :column-num="5">
      <van-grid-item
        @click="Jump(value)"
        v-for="value in orderList"
        :key="value.id"
        :icon="value.icon"
        :text="value.text"
      />
    </van-grid>
    <div class="tool">
      <p>必备工具</p>
    </div>
  </div>
</template>

<script>
import {post} from '../utils/request'
import { ImagePreview } from 'vant';
import { getImg } from '../utils/auth.js'
export default {
  name: "User",
  data() {
    return {
      orderList: [
        {
          id: 1,
          name: "待付款",
          icon: "pending-payment",
          text: "待付款",
        },
        {
          id: 2,
          name: "待发货",
          icon: "paid",
          text: "待发货",
        },
        {
          id: 3,
          name: "待收货",
          icon: "logistics",
          text: "待收货",
        },
        {
          id: 4,
          name: "评价",
          icon: "chat-o",
          text: "评价",
        },
        {
          id: 5,
          name: "退货/售后",
          icon: "balance-o",
          text: "退货/售后",
        },
      ],
      img: '',
      titleName: ''
    };
  },
  methods: {
    Jump(item) {
      if (
        item.text == "待付款" ||
        item.text == "待发货" ||
        item.text == "待收货" ||
        item.text == "评价"
      ) {
        this.$router.push({
          name: "Order",
        });
        console.log(item.name);
        this.$store.commit("OrderName", item.name);
      }
    },
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      console.log(file);
      const formData = new FormData()
      formData.append('file', file.file)
      post('/api/v1/common/file_upload', formData).then((res) => {this.touxiang = res.info
      console.log(res.info)
      })
    },
    T_SetUp() {
      this.$router.push({
        name: "SetUp",
      });
    },
  },
  created() {
    this.img = getImg()
    console.log(this.$store.state.name)
    this.titleName = this.$store.state.name.userName
  }
};
</script>

<style scoped>
.user .portrait {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-right: 10px;
  font-size: 24px;
  overflow: hidden;
}
.user .yanse {
  background: #db5a6b;
}
.user .user_head {
  width: 94%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
}
.user .head_lfet {
  display: flex;
  justify-content: flex-start;
}
.user .head_lfet .user_m {
  font-size: 20px;
}
.user .head_right {
  width: 20%;
  padding-top: 16px;
  display: flex;
  justify-content: space-between;
}
.user .head_right .ic_size {
  font-size: 24px;
  /* color: red; */
}
.user .head_right .ic_lfet {
  margin-right: 20px;
}
.user .user_ul {
  display: flex;
  justify-content: space-around;
  /* align-items: center; */
  text-align: center;
}
.user .tool {
  width: 94%;
  margin: 0 auto;
}
</style>